import { v4 as uuidv4 } from 'uuid';

export default {
  use(app, knex){

    //查询产品信息
    app.get('/productInfo', function(req, res){
      knex('product_info')
      // .where({user_id: req.user_id})
      .limit(1)
      .select('*').then(rows=>{
        res.send({
          code: 0,
          data: rows[0]
        })
      })  
      .catch(err => {
        console.log(err)
        res.send({
          code: 1,
          message: err
        })
      })
    })



    
    //更新产品信息
    app.post('/productInfo/update', function(req, res){
      const data = req.body;
      const id = data.id;
      delete data.id;
      knex('product_info')
      .where('id', '=', id)
      .update({
        ...data
      })
      .then(row => {
        res.send({
          code: 0,
          data: '更新产品信息成功'
        })
      })
      .catch(err => {
        res.send({
          code: 1,
          message: err
        })
      })
    })
  }
}

